<template>
  <div>
    <van-nav-bar
      title="设置昵称"
      left-text="取消"
      right-text="完成"
      @click-left="$emit('close')"
      @click-right="onClickRight"
    />
    <div class="filed-wrap">
      <van-field
        v-model="message"
        rows="2"
        autosize
        type="textarea"
        maxlength="50"
        placeholder="请输入昵称"
        show-word-limit
      />
    </div>
  </div>
</template>

<script>
// eslint-disable-next-line no-unused-vars
import { updateUserProfile } from '@/api/user'
export default {
  name: 'UpdateName',
  props: {
    value: {
      type: String,
      required: true
    }
  },
  components: {},
  data () {
    return {
      message: this.value
    }
  },
  created () {

  },
  methods: {
    async onClickRight () {
      this.$toast.loading({
        message: '保存中',
        duration: 0,
        forbidClick: true
      })
      await updateUserProfile({
        name: this.message
      })
      this.$toast.success({
        message: '更新成功'
      })
      this.$emit('input', this.message)
      this.$emit('close')
    }
  }
}
</script>

<style lang="less" scoped>
.filed-wrap {
  padding: 20px;
}
</style>
